package org.example;
import java.sql.*;
public class PetADD {
    private static final String INSERT_PET_SQL =
            "INSERT INTO pets (name, breed, age, price, status, description, species) VALUES (?, ?, ?, ?, ?, ?, ?)";

    public void addPet(Pet pet) throws SQLException {
        try (Connection conn = JDBCDemo.getConnection();
             PreparedStatement pstmt = conn.prepareStatement(INSERT_PET_SQL)) {

            pstmt.setString(1, pet.getName());
            pstmt.setString(2, pet.getBreed());
            pstmt.setInt(3, pet.getAge());
            pstmt.setInt(4, pet.getPrice()); // 注意：你用的是 int price，不是 double
            pstmt.setString(5, pet.isAvailable() ? "available" : "adopted");
            pstmt.setString(6, pet.getDescription());
            pstmt.setString(7, pet.getSpecies()); // ✅ 关键修改！

            pstmt.executeUpdate();
            System.out.println("宠物 [" + pet.getName() + "] 已成功保存到数据库！");
        }
    }
}